Skip to content

ColorComboBox

Base classes

Name Children Inherits
ComboBox
prettyqt.widgets.combobox
Combined button and popup list.

⋔ Inheritance diagram

graph TD
  2476246951["custom_widgets.ColorComboBox"]
  2460391555["widgets.ComboBox"]
  1955118198["widgets.ComboBoxMixin"]
  829357528["widgets.WidgetMixin"]
  3227531497["core.ObjectMixin"]
  2751680898["builtins.object"]
  625385617["gui.PaintDeviceMixin"]
  1844689747["QtWidgets.QComboBox"]
  3620195106["QtWidgets.QWidget"]
  3984060476["QtCore.QObject"]
  37984305["Shiboken.Object"]
  673956333["QtGui.QPaintDevice"]
  2460391555 --> 2476246951
  1955118198 --> 2460391555
  829357528 --> 1955118198
  3227531497 --> 829357528
  2751680898 --> 3227531497
  625385617 --> 829357528
  2751680898 --> 625385617
  1844689747 --> 2460391555
  3620195106 --> 1844689747
  3984060476 --> 3620195106
  37984305 --> 3984060476
  2751680898 --> 37984305
  673956333 --> 3620195106
  37984305 --> 673956333

🛈 DocStrings

Bases: ComboBox

Source code in prettyqt/custom_widgets/editors/colorcombobox.py
class ColorComboBox(widgets.ComboBox):
    value_changed = core.Signal(gui.QColor)

    def __init__(
        self,
        color: datatypes.ColorType | None = None,
        object_name: str = "color_combobox",
        **kwargs,
    ):
        super().__init__(object_name=object_name, **kwargs)
        self._current_color: gui.QColor = gui.QColor("white")
        for i in gui.Color.colorNames():
            self.addItem(iconprovider.for_color(i), i)
        if color is not None:
            self.set_current_color(color)
        self.currentTextChanged.connect(self.set_current_color)

    def __repr__(self):
        return get_repr(self, self._current_color)

    def clear(self):
        self._current_color = gui.QColor("white")
        super().clear()
        for i in gui.Color.colorNames():
            self.addItem(iconprovider.for_color(i), i)

    def set_current_color(self, color: datatypes.ColorType):
        self._current_color = colors.get_color(color).as_qt()
        for color_name in gui.Color.colorNames():
            if gui.Color(color_name) == self._current_color:
                self.setCurrentText(color_name)
                return

    def is_valid(self) -> bool:
        return self._current_color.isValid()

    def get_value(self) -> gui.QColor:
        return self._current_color

    def set_value(self, value: datatypes.ColorType):
        self.set_current_color(value)

    current_color = core.Property(
        gui.QColor,
        get_value,
        set_value,
        user=True,
        doc="Currently selected color",
    )

:fa-brands-github: Show source on GitHub